<!--/**
*注册1 *
*
* @author LWG
* @date 2022/7/19 15:12
* @since 1.0.0
*/-->
<template>
  <div>
    <div class="top">
      <!-- 顶部背景图片 -->
      <div class="bgImg">
      </div>
      <!-- logo图片 -->
      <div class="logo">
        <img class="logo_img" src="../../../assets/logo.png" />
      </div>
      <div class="empty" >

      </div>
      <van-nav-bar
          title="时光源注册"
      />
      <van-form @submit="onSubmit">
        <van-field
            v-model="username"
            name="账号"
            label="账号"
            placeholder="账号"
            :rules="[{ required: true, message: '请填写手机号或邮箱号' }]"
        />
        <van-field
            v-model="password"
            type="password"
            name="密码"
            label="密码"
            placeholder="密码"
            :rules="[{ required: true, message: '请填写密码' }]"
        />
        <van-field
            v-model="RePassword"
            type="RePassword"
            name="确认密码"
            label="确认密码"
            placeholder="确认密码"
            :rules="[{ required: true, message: '请确认密码' }]"
        />
        <van-field
            v-model="pin"
            type="pin"
            name="验证码"
            label="验证码"
            placeholder="验证码"
            :rules="[{ required: true, message: '请输入验证码码' }]"
        >
          <van-button slot="button"
                      plain hailine type="info" round
                      size="small"
                      @click="gainCode">{{time}}</van-button>
        </van-field>
        <van-row gutter="24" style="margin-top: 30px">
          <van-col span="6"></van-col>
          <van-col span="6">
            <router-link to="/login">
              <van-button round block plain hairline type="info" size="small" native-type="submit">登录</van-button>
            </router-link>
          </van-col>
            <van-col span="6">
              <van-button round block plain hairline type="info" size="small" native-type="submit" @click="register">下一步</van-button>
            </van-col>

          <van-col span="6"></van-col>
        </van-row>
      </van-form>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant';
export default {
  name: 'Registry',
  data() {
    return {
      password: '',
      username: '',
      RePassword: '',
      pin: '',
      time: '获取验证码'
    }
  },
  methods: {
    register() {
      console.log('11111111111')
      if(this.password==''||this.username==''||this.RePassword==''||this.pin==''){
        Toast("信息不能为空")
        return
      }
      if(this.password!=this.RePassword){
        Toast("密码不匹配")
        return
      }
      const url = 'http://localhost:10002/ums/user/add-new'
      const dat = {
        password: this.password,
        phone: this.username,
        verifCode: this.pin

      }
      console.log(dat)
      this.axios.post(url,dat).then(response => {
        console.log(response.data)
        if(response.data.state == 200){

            console.log('注册成功')
            console.log(response.data.data)
            this.$router.push('/registry/detail?userId='+response.data.data)
        }
        else{
          setTimeout(() => {
            Toast(response.data.message).close(), 1000
          })
        }
      })
    },
    onClickLeft() {
      Toast('返回');
      history.go(-1)
    },
  },
};
</script>

<style>
.bgImg {
  width: 100vw;
  height: 30vh;
  z-index: 1;
  background-image: url("https://img01.yzcdn.cn/vant/cat.jpeg");
  background-size: 100%;
}
.logo {
  position: absolute;
  width: 40vw;
  height: 15vh;
  top: 20vh;
  left: 30vw;
  background-color: #ffffff;
  border-radius: 60%;
  z-index: 2;
}
.logo_img {
  width: 150%;
  height: 150%;
  margin-left: -10vw;
  margin-top: -5vh;
}
.empty {
  height: 5vh;
}
</style>

